/*
 *  elasticlog.cpp
 *  EPPI-0.0
 *
 *  Created by Juan Carlos García Orden on 19/11/07.
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
 *
 */

#include "elasticlog.h"

ElasticLog::ElasticLog()
:	HyperelasticStretches(),
	E(0.0),
	nu(0.3),
	strain(0.0)
{}

// ***

ElasticLog::ElasticLog(ifstream &in, const string& na, const string & t)
:	HyperelasticStretches(na,t),
	E(0.0),
	nu(0.3),
	strain(0.0)
{
	string keyword;
	while (in >> keyword && keyword.compare("ENDMATERIAL") )
	{
		if(!keyword.compare("E"))	in >> E;
		else if(!keyword.compare("NU"))	in >> nu; 	
		else if(!keyword.compare("DENSITY"))	in >> density;		
	}

	mu = E / 2.0 / (1.0 + nu);
	lambda = nu * E / (1.0 + nu) / (1.0 - 2.0 * nu);
	
	hypertype = "coupled";
}

// ***
// ***

void ElasticLog::strainEnergy()
{
	if(lambda1!=0.0)
	{	
		strain = log(lambda1);
		
		W = 0.5 * E * strain * strain;
	}
	else
	{
		cout << "*ERROR: stretch is zero, material " << name << " has collapsed \n";
		W = -1.0;
	}
}

void ElasticLog::DstrainEnergy()
{
	if(lambda1!=0.0) 
	{
		W1 = E * log(lambda1)/ lambda1;
		W2 = 0.0;
		W3 = 0.0;
	}
	else
	{
		W1 = -1.0;
	}
}

// ***

void ElasticLog::DDstrainEnergy()
{
	if(lambda1 != 0.0)
	{
		W11 = E * (1.0 - log(lambda1)) /  ( lambda1 * lambda1 );
		W12 = 0.0;
		W13 = 0.0;
		W22 = 0.0;
		W23 = 0.0;
		W33 = 0.0;
	}
	else
	{
		W11 = - 1.0;
		W12 = - 1.0;
		W13 = - 1.0;
		W22 = - 1.0;
		W23 = - 1.0;
		W33 = - 1.0;
	}
}

// ***

void ElasticLog::DDDstrainEnergy()
{}

// ***

double ElasticLog::getE()
{	return E;}

// ***

double ElasticLog::getNu()
{	return nu;}

// ***

double ElasticLog::getLambda()
{	return lambda;}

// ***

double ElasticLog::getMu()
{	return mu;}

// ***

double ElasticLog::getDensity()
{	return density;}

// ***